Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop request.timer attribute. #1249

Merged
merged 5 commits into from
Sep 7, 2020
Merged

Drop request.timer attribute. #1249

merged 5 commits into from
Sep 7, 2020

Conversation

tomchristie
Copy link
Member

@tomchristie tomchristie commented Sep 2, 2020

Minor bit of refactoring. We don't really want a request.timer attribute in our public API, exposing an internal ElapsedTimer instance.

Instead support a Response(..., stream=..., get_elapsed_time=...) parameter, which allows passing in a callable that is used to set response.elapsed when the response is closed. We don't particularly expect our users to need to use this, but it's a little neater and more tightly scoped than having an accessible timer on the request instance.

Also allows us to use a backend-native timer, appropriate to whichever context we're running in.

@tomchristie tomchristie added the refactor Issues and PRs related to code refactoring label Sep 2, 2020
Copy link
Contributor

@StephenBrown2 StephenBrown2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice bit of uncoupling. Left a sanity check question but this looks good!

tests/models/test_responses.py Show resolved Hide resolved
florimondmanca
florimondmanca previously approved these changes Sep 3, 2020
@tomchristie
Copy link
Member Author

Before we merge this, do we think we've got the right name?
Some options might be...

  • get_elapsed_time=... Currently using, in this PR
  • elapsed_timer=...
  • elapsed_callable=...
  • elapsed_time=...
  • elapsed_func=...

Anything else? Which of those is preferable?

@florimondmanca
Copy link
Member

elapsed_func=...

Yup, I think I prefer this one better. (True that .get_elapsed_time looks like a method rather than an externally-passed argument.)

@florimondmanca florimondmanca dismissed their stale review September 6, 2020 16:02

Wait for elapsed_func

@tomchristie tomchristie merged commit a783fe5 into master Sep 7, 2020
@tomchristie tomchristie deleted the drop-request-timer branch September 7, 2020 08:06
@tomchristie tomchristie mentioned this pull request Sep 21, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Issues and PRs related to code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants